import java.applet.*; import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class AppTest extends Applet { //data fields (for convenience only) public int xMax; public int yMax; //Initializer - This method is automatically ran with applet is loaded! //It sorta replaces the constructor. public void init() { xMax = getSize().width-1; yMax = getSize().height-1; } //Paint - This method is automatically ran when the applet has to be repainted. public void paint( Graphics g ) { //Working with a 2D class will give us extra options. Graphics2D g2D = (Graphics2D) g; //Draw biggest rectangle using lines & points Point2D.Double topLeft = new Point2D.Double(0.0, 0.0); Point2D.Double topRight = new Point2D.Double(xMax, 0.0); Point2D.Double bottomLeft = new Point2D.Double(0.0, yMax); Point2D.Double bottomRight = new Point2D.Double(xMax, yMax); Line2D.Double top = new Line2D.Double(topLeft, topRight); Line2D.Double right = new Line2D.Double(topRight, bottomRight); Line2D.Double bottom = new Line2D.Double(bottomRight, bottomLeft); Line2D.Double left = new Line2D.Double(bottomLeft, topLeft); g2D.draw(top); g2D.draw(right); g2D.draw(bottom); g2D.draw(left); //draw X Line2D.Double diag1 = new Line2D.Double(topLeft, bottomRight); Line2D.Double diag2 = new Line2D.Double(topRight, bottomLeft); g2D.draw(diag1); g2D.draw(diag2); } }